<template>
    <view class="content">
        <view class="item" v-for="(item, index) in list" :key="index">
            <image :src="IMAGEURL + 'static/image/cou_bg.png'" class="cou-bg"></image>
            <view class="item-cou">
                <view class="item-cou-l">
                    <view>
                        <text class="cou-num">{{item.money}}</text>
                        <text>元</text>
                    </view>
                    <view>满{{item.full_money}}可用</view>
                </view>
                <view class="item-cou-r">
                    <view class="u-flex-1">
                        <view class="u-font-30 u-p-b-5 text-bold">{{item.name}}</view>
                        <view class="cou-time">有效期至{{item.end_time}}</view>
                        <!-- <view class="cou-time">本券剩余{{item.num}}张</view> -->
                    </view>
                    <view class="cou-btn" @click="doReceive(item)">选择使用</view>
                </view>
            </view>
        </view>
        
        <view style="height: 94rpx;padding-top: 30rpx;">
            <u-loadmore :status="status" v-if="status != 'loadmore'" />
        </view>
    </view>
</template>

<script>
    import { IMAGEURL } from '@/static/js/common.js';
    export default {
        data() {
            return {
                IMAGEURL,
                status: 'loadmore', //是否显示没有更多了
                page: 1,
                list: [],
                money: 0,
            };
        },
        onLoad(option) {
            this.money = option.money
            this.getList()
        },
        onReachBottom() {
        	if(this.page == 1){return}
        	this.getList()
        },
        methods: {
            // 选择使用
            doReceive(item) {
                uni.$emit('ChooseCoupon', item)
                this.$backT()
            },
            
            // 获取列表
            getList() {
            	if (this.status == 'nomore') return;
            	this.status = 'loading';
            	this.$ajax('user_coupon', {
            		user_token: this.$getSync('userToken'),
            		page: this.page,
            		limit: 10,
                    status: 1,//0未领取 1未使用 2已使用 3已过期
                    money: this.money,//订单金额 满足使用条件
            	}).then(ret => {
            		if (ret.success == 1000) {
            			if (ret.detail && ret.detail.coupon && ret.detail.coupon.length > 0) {
            				this.list = this.list.concat(ret.detail.coupon);
            				this.page++;
            				this.status = 'loadmore'
            			} else {
            				this.status = 'nomore'
            			}
            		} else {
            			this.$toast(ret.msg);
            		}
            	});
            },
        }
    };
</script>

<style lang="scss">
    page{
        background-color: #f5f5f5;
    }
    .content{
        padding: 20rpx;
    }
    .item{
        position: relative;
        margin-bottom: 20rpx;
    }
    .cou-bg{
        width: 706rpx;
        height: 165rpx;
    }
    .item-cou{
        width: 670rpx;
        height: 165rpx;
        display: flex;
        justify-content: space-between;
        align-items: center;
        position: absolute;
        left: 20rpx;
        top: 0;
    }
    .item-cou-l{
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
    }
    .cou-num{
        font-size: 44rpx;
        font-weight: bold;
    }
    .item-cou-r{
        padding-left: 50rpx;
        flex: 1;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    .cou-time{
        font-size: 24rpx;
        color: #636363;
    }
    .cou-btn{
        font-size: 25rpx;
        color: #fff;
        padding: 15rpx 20rpx;
        background-color: #f29700;
        border-radius: 50rpx;
    }

</style>
